//
//  YMHomeViewController.swift
//  Driver
//
//  Created by lantaiyuan on 2017/10/31.
//  Copyright © 2017年 youmy. All rights reserved.
//

import UIKit
import MJExtension

class YMHomeViewController: UIViewController {
    
    @IBOutlet weak var CircleConstraintW: NSLayoutConstraint!
    
    @IBOutlet weak var CircleConstraintH: NSLayoutConstraint!
    
    @IBOutlet weak var bottomConstraintH: NSLayoutConstraint!
    
    @IBOutlet weak var auditView: YMUIView!
    
    @IBOutlet weak var auditLb: UILabel!
    
    @IBOutlet weak var takePassengerView: YMUIView!
    
    @IBOutlet weak var startLb: UILabel!
    
    @IBOutlet weak var endLb: UILabel!
    
    @IBOutlet weak var orderNumLb: UILabel!
    
    @IBOutlet weak var hourLb: UILabel!
    
    @IBOutlet weak var chucheBtn: UIButton!
    
    @IBOutlet weak var shoucheBtn: UIButton!
    
    
    @IBAction func chucheBtnAction(_ sender: UIButton) {
    }
    
    @IBAction func shoucheBtnAction(_ sender: UIButton) {
    }
    
    // take passenger
    @IBAction func takePassengerBtn(_ sender: UIButton) {
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        defaultConfig()
        
        coreText(auditLb, subString: "正在审核中", fontSize: 14, fontColor: greenColor, textAlign: .center)
        coreText(orderNumLb, subString: "单", fontSize: 14, fontColor: nil, textAlign: .left)
        coreText(hourLb, subString: "时", fontSize: 14, fontColor: nil, textAlign: .right)
        
        hourLb.text="89989时"
        refreshLabel()
    }
    
    // default config
    fileprivate func defaultConfig(){
        takePassengerView.isHidden = true
        shoucheBtn.isHidden = true
        
        let wh = view.bounds.width / 2.0
        CircleConstraintW.constant = wh
        CircleConstraintH.constant = wh
    }
    
    // refresh label
    fileprivate func refreshLabel(){
        coreText(orderNumLb, subString: "单", fontSize: 14, fontColor: nil, textAlign: .left)
        coreText(hourLb, subString: "时", fontSize: 14, fontColor: nil, textAlign: .right)
    }

    
    fileprivate func coreText(_ label:UILabel, subString: String, fontSize: CGFloat, fontColor: UIColor?, textAlign: NSTextAlignment){
        let str: NSMutableAttributedString = NSMutableAttributedString(string: label.text ?? "")
        let totalStr = label.text! as NSString
        let range = totalStr.range(of: subString)
        str.lineSpacing = 5.0
        
        str.addAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: fontSize),
                           NSForegroundColorAttributeName: fontColor ?? label.textColor as Any], range: range)
        label.attributedText = str
        label.textAlignment = textAlign
    }
    
}


extension YMHomeViewController {
    
}
